package com.yiyaOvo.cloudDisk;

import com.yiyaOvo.cloudDisk.pojo.FileItem;
import com.yiyaOvo.cloudDisk.utils.NetworkUtils;

import java.util.List;
import java.util.Scanner;

/**
 * User: yiyaOvo
 * Date: 2021/5/23
 * Time: 15:43
 * role: cloud disk client
 */
public class Client {

    Scanner sc = new Scanner(System.in);

    /**
     * show files
     */
    public void showFileList() {
        List<FileItem> fileItems = NetworkUtils.getFileItems();
        fileItems.forEach(fileItem -> {
            System.out.printf("id: %d\tfileName: %s\tlength: %d\n", fileItem.getId(), fileItem.getFileName(),
                    fileItem.getLength());
        });
    }

    /**
     * upload file
     */
    public void uploadFile() {
        System.out.println("please input file path:");
        String filePath = sc.next();
        NetworkUtils.uploadFile(filePath);
    }

    /**
     * download file
     */
    public void downloadFile() {
        System.out.println("please input file name:");
        String fileName = sc.next();
        NetworkUtils.downloadFile(fileName);
    }

    /**
     * delete file
     */
    public void deleteFile() {
        System.out.println("please input file name:");
        String fileName = sc.next();
        NetworkUtils.deleteFile(fileName);
    }

    /**
     * start client
     */
    public void start() {
        System.out.println("client have start!!!");
        while (true) {
            System.out.println("please choose operation 1:query 2:upload 3:download 4:delete others num is " +
                                       "logout");
            int type = sc.nextInt();
            switch (type) {
                case 1:
                    showFileList();
                    break;
                case 2:
                    uploadFile();
                    break;
                case 3:
                    downloadFile();
                    break;
                case 4:
                    deleteFile();
                    break;
                default:
                    return;
            }
        }
    }

    public static void main(String[] args) {
        new Client().start();
    }
}
